package com.leoman.plz_p.weidget;

import android.app.Activity;
import android.support.v4.content.ContextCompat;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.leoman.plz_p.R;


public class ChooseAvatarPopupWindow extends AlphaPopupWindow {
    private OnTypeChosenListener listener;

    private View.OnClickListener dismiss = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dismiss();
        }
    };

    public ChooseAvatarPopupWindow(Activity context) {
        super(context);
        init(context);
    }

    private void init(Activity context) {
        View view = LayoutInflater.from(context).inflate(R.layout.view_choose_avatar, null);

        setContentView(view);
        setWidth(WindowManager.LayoutParams.MATCH_PARENT);
        setHeight(WindowManager.LayoutParams.MATCH_PARENT);

        setFocusable(true);
        setOutsideTouchable(true);
        setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.pop_bg));
        setAnimationStyle(R.style.anim_style);

        TextView camera = (TextView) view.findViewById(R.id.tv_camera);
        TextView gallery = (TextView) view.findViewById(R.id.tv_gallery);

        TextView cancel = (TextView) view.findViewById(R.id.tv_cancel);

        cancel.setOnClickListener(dismiss);
        view.setOnClickListener(dismiss);

        camera.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) listener.onCamera();
                dismiss();
            }
        });

        gallery.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) listener.onGallery();
                dismiss();
            }
        });
    }

    public void showAtBottom(View view) {
        showAtLocation(view, Gravity.BOTTOM, 0, 0);
    }

    public void setOnTypeChosenListener(OnTypeChosenListener l) {
        listener = l;
    }

    public interface OnTypeChosenListener {
        void onCamera();
        void onGallery();
    }

}

